package com.cn.intelligence.util;

import java.util.HashMap;
import java.util.Map;

import com.cn.intelligence.pojo.AccessToken;
import com.cn.intelligence.pojo.TemplateValue;

import net.sf.json.JSONObject;

public class SendWxTemplateMessage {

	private final static String APPID = "wxbf146818744d6146";

	private final static String APPSECRET = "14d26abc620743d9d76e3abe1e03df4b";

	public static void sender(String touser,String form_id, Map<String, Object> map1) throws Exception {
		
		
		JSONObject jsonStr = new JSONObject();
		jsonStr.element("offset", 0);
		jsonStr.element("count", 2);
		AccessToken ac=WeixinUtil.getAccessToken(APPID, APPSECRET);
		
		String s = WeixinUtil.getTemplateList(jsonStr.toString(), ac.getToken());
		System.out.println(ac.getToken());
		System.out.println(s);
		System.out.println("------------------");
		System.out.println(form_id);
		System.out.println("------------------");
		JSONObject jsonStr1 = new JSONObject();
		jsonStr1.element("touser", touser);
		jsonStr1.element("template_id", "C5LobYLlCg5xDlz7ryJERHwRT8zjAtWTOoCZHH-Fo94");
		jsonStr1.element("page", "pages/index/index");
		jsonStr1.element("form_id", form_id);
/*		TemplateValue list = new TemplateValue();
		list.setValue("339208499");
		list.setColor("#173177");
		Map<String,Object> mapt = new HashMap<String,Object>();
		mapt.put("keyword1",list);
		mapt.put("keyword2",list);
		mapt.put("keyword3",list);
		mapt.put("keyword4",list);*/
		
		jsonStr1.element("data", map1);
		jsonStr1.element("emphasis_keyword", "keyword1.DATA");
		
//		  "template_id": "TEMPLATE_ID", 
//		  "page": "index",          
//		  "form_id": "FORMID",         
//		  "data": {
//		      "keyword1": {
//		          "value": "339208499", 
//		          "color": "#173177"
//		      }, 
//		      "keyword2": {
//		          "value": "2015年01月05日 12:30", 
//		          "color": "#173177"
//		      }, 
//		      "keyword3": {
//		          "value": "粤海喜来登酒店", 
//		          "color": "#173177"
//		      } , 
//		      "keyword4": {
//		          "value": "广州市天河区天河路208号", 
//		          "color": "#173177"
//		      } 
//		  },
//		  "emphasis_keyword": "keyword1.DATA" 
//		}
		System.out.println("----------dsdsdsd--------");
		System.out.println(jsonStr1.toString());
		String string = WeixinUtil.sendTemplateMsg(jsonStr1.toString(), ac.getToken());
		System.out.println(string);
		
	}
}